<%@page import="java.sql.Date"%>
<%@page import="Entity.Room_ced"%>
<%@page import="java.sql.*"%>
<%@page import="Dao.scheduledao"%>
<%@page import="Entity.Course"%>
<%@page import="Entity.Self_Booked_Page"%>
<%@page import="java.text.SimpleDateFormat"%>
<%@page import="Entity.User"%>
<%@ page language="java" import="java.util.*" pageEncoding="UTF-8"%>
<%
String path = request.getContextPath();
String basePath = request.getScheme()+"://"+request.getServerName()+":"+request.getServerPort()+path+"/";
%>

<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN">
<html>
  <head>
    <base href="<%=basePath%>">
    
    <title>My JSP 't_check.jsp' starting page</title>
    
	<meta http-equiv="pragma" content="no-cache">
	<meta http-equiv="cache-control" content="no-cache">
	<meta http-equiv="expires" content="0">    
	<meta http-equiv="keywords" content="keyword1,keyword2,keyword3">
	<meta http-equiv="description" content="This is my page">
	<meta content="width=device-width,initial-scale=1.0,maximum-scale=1.0,user-scalable=0" name="viewport">
	<!--
	<link rel="stylesheet" type="text/css" href="styles.css">
	-->
	<link href="https://cdn.staticfile.org/twitter-bootstrap/3.3.7/css/bootstrap.min.css" rel="stylesheet">
	<script src="https://cdn.staticfile.org/jquery/2.1.1/jquery.min.js"></script>
	<script src="https://cdn.staticfile.org/twitter-bootstrap/3.3.7/js/bootstrap.min.js"></script>
	<link rel="stylesheet" href="https://cdnjs.cloudflare.com/ajax/libs/font-awesome/4.7.0/css/font-awesome.min.css" integrity="sha512-SfTiTlX6kk+qitfevl/7LibUOeJWlt9rbyDn92a1DqWOw9vWG2MFoays0sgObmWazO5BQPiFucnnEAjpAB+/Sw==" crossorigin="anonymous" referrerpolicy="no-referrer" />
	<link rel="shortcut icon" type="image/x-icon" href="logo.jpg" />
	<style>
		body {
		  font-family: Arial;
		  background-image: linear-gradient(to top, #e6e9f0 0%, #eef1f5 100%);
		}
		
		* {
		  box-sizing: border-box;
		}
		a {
		text-decoration: none;
		}
		form.example input[type=text] {
		  padding: 10px;
		  font-size: 17px;
		  border: 1px solid grey;
		  float: left;
		  width: 80%;
		  background: #f1f1f1;
		}
		
		form.example button {
		  float: left;
		  width: 20%;
		  padding: 10px;
		  background: #2196F3;
		  color: white;
		  font-size: 17px;
		  border: 1px solid grey;
		  border-left: none;
		  cursor: pointer;
		}
		
		form.example button:hover {
		  background: #0b7dda;
		}
		
		form.example::after {
		  content: "";
		  clear: both;
		  display: table;
		}
	</style>
  </head>
  
  <body>
   <%
   User user =(User) session.getAttribute("user");
  	 if(user==null){
  	 	 request.getRequestDispatcher("login.jsp").forward(request,response);
  	 }
  	 String id=user.getUid(); 
	 
  	 if(request.getAttribute("sbp")==null){
  	 	response.sendRedirect("Self_boocked?page_n=1");
  	 }
  	  Self_Booked_Page sbp = (Self_Booked_Page)request.getAttribute("sbp");
  	 %>
  		<!-- 顶部-->
    	<div style="border: 1px;display: block;">
    			<image  src="image/title.png" style="width: 600px;">
    			<a href="personInfor.jsp" class="btn dropdown-toggle"  style="float: right;margin:auto 40px;">
    			<i class="fa fa-user-circle fa-2x"></i>
    			个人信息
		   		 </a>
    	</div>
    		<!-- 导航-->
    		<div style="float: left;width: 10%;height:90%; bottom:0;display: block;border-radius: 10px;
   		background-image: linear-gradient(to top, #accbee 0%, #e7f0fd 100%);">
    			<ul class="nav nav-pills nav-stacked">
				  <li><a href="class_total.jsp">创建课程</a></li>
				  <li class="active"><a href="Self_boocked?page_n=1">查看课程</a></li>
				  <li><a href="Notice1Servlet">收件箱</a></li>
				</ul>
    		</div>
 
		    <div class="table-responsive" style="padding: 2rem;width:85%;height: 100%;float: left: ;">
		    <table  class="table table-hover" style="margin: auto;line-height: 50px;">
			    <thead>
			     	<tr  class="info">
			        <th>课程编号</th>
			        <th>课程名称</th>
			        <th>时间</th>
			        <th>机房</th>
			        <th>学生数量</th>
			        <th>操作</th></tr>
			    </thead>
			    <tbody>
			 <% if(sbp!=null){
			 System.out.println("现在的sbp是："+sbp);
			 	List<Course> courses=sbp.getC_list();
			 	System.out.println("现在的courses是："+courses);
			 	if(courses!=null){
					for(Course course:courses){
					String course_id=course.getCourse_Id();
					scheduledao sced = new scheduledao();
					System.out.println(course_id);
					Room_ced ced=sced.getSchedule(course_id);
					Date cdata= ced.getDate();
					
					%>
					<tr>
					<td><%=course.getCourse_Id() %></td>
					<td><%=course.getCourse_Name()%></td>
					<td><%=cdata.toString() %></td>
					<td><%=ced.getRoom_Id() %></td>
					<td><%=course.getstu_Num() %></td>
					<td><a href="DeleteCourseServlet?cid=<%=course.getCourse_Id()%>">删除</a></td>
					</tr>
					<%
					}
					}
					}
					 %>   
				</tbody>
			
		    </table>
		    <div style="text-align: center;margin: 20px auto;">
		   <%
					if(sbp.getPage_n()==1){
						if(sbp.getPage_n()!=sbp.getSum()){
					
					%>
							共<%=sbp.getPage_n() %>/<%=sbp.getSum() %>页
							<a href="Self_boocked?page_n=<%=sbp.getPage_n()+1%>">下一页</a>
							<a href="Self_boocked?page_n=<%=sbp.getSum()%>">尾页</a>
					<%
						}else if(sbp.getPage_n()==sbp.getSum()){
						%>
							共1/1页
						<%
						}
					}else if(sbp.getPage_n()==sbp.getSum()){
						%>
							共<%=sbp.getPage_n() %>/<%=sbp.getSum() %>页
							<a href="Self_boocked?page_n=1">首页</a>
							<a href="Self_boocked?page_n=<%=sbp.getPage_n()-1%> %>">上一页</a>
						<%
					}else{
						%>
							<a href="Self_boocked?page_n=1">首页</a>
							<a href="Self_boocked?page_n=<%=sbp.getPage_n()-1%> %>">上一页</a>
							共<%=sbp.getPage_n() %>/<%=sbp.getSum() %>页
							<a href="Self_boocked?page_n=<%=sbp.getPage_n()+1%> %>">下一页</a>
							<a href="Self_boocked?page_n=<%=sbp.getSum()%> %>">尾页</a>
						<%
					}
					
				 %>
		    </div>
	    </div>
  </body>
</html>
